from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponse

def HttpError(request, code):
    if code == 403:
        error_type = 'HTTP 403: Forbidden'
        error_message = 'You might not have permission to access this page.'
    elif code == 404:
        error_type = 'HTTP 404: Not Found'
        error_message = 'Invalid Request. You requested a page that does not exist.'
    elif code == 500:
        error_type = 'HTTP 500: Internal Server Error'
        error_message = 'Internal Server Error.'
    else:
        error_type = 'Unknow error'
        error_message = 'Please contact to admin.'

    return render_to_response(
        'blog/http_error.html',
        {'error_type': error_type, 'error_message': error_message},
        RequestContext(request),
    )

def HttpError403(request):
    return HttpError(request, 403)

def HttpError404(request):
    return HttpError(request, 404)

def HttpError500(request):
    return HttpError(request, 500)